<template>
  <div class="app-container">

    <div class="filter-container">

      <el-button @click="getRecords" type="danger" class="filter-item">刷新</el-button>
    </div>

    <el-table
      v-horizontal-scroll="'always'"
      v-loading="listLoading"	:data="list"	element-loading-text="Loading"	border	fit	highlight-current-row>
      <!-- <el-table-column type="selection" width="55" /> -->
      <!-- <el-table-column type="index" label="序列" width="50" /> -->
      <el-table-column prop="id" label="ID" min-width="80" />
      <el-table-column prop="userId" label="用户ID" min-width="100" />
      <el-table-column prop="avatar" label="头像" min-width="80" >
        <template slot-scope="scope">
          <img v-if="scope.row.avatar" class="table-img" :src="scope.row.avatar">
        </template>
      </el-table-column>
      <el-table-column prop="nick_name" label="用户名" min-width="120" />
      <el-table-column prop="count" label="总观看次数" min-width="80" />
      <el-table-column  prop="logs" label="记录" min-width="300" />
      <el-table-column fixed="right" label="操作" min-width="100">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="detail(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--<el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagination.page"
      :page-sizes="[10, 20, 100, 200]"
      :page-size="pagination.pageSize"
      :background="true"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagination.total">
    </el-pagination>-->
  </div>
</template>

<script>

import { myGet,myPost } from '@/utils/myRequest'

const urlSeeLog = '/guard/user/seeLog';
const urlSeeLogDetail = '/guard/user/detail';

export default {

  data() {
    return {
      host:process.env.VUE_APP_HOST,
      pagination:{
        total:0,
        page:1,
        pageSize:20,
      },
      list: [],
      formLoading:false,
      listLoading: true
    }
  },
  methods: {
    reload(){
      //Object.assign(this.$data.query,this.$options.data().query)
      Object.assign(this.$data.pagination,this.$options.data().pagination)
      this.getRecords()
    },
    getRecords(){
      this.list = []
      this.listLoading = true;
      let params = Object.assign(this.pagination)
      myGet(urlSeeLog,params).then((res) =>{
        this.listLoading = false;
        if(res.status){

          this.list = res.data.records
          this.pagination.total = res.data.total
        }
      })
    },
    handleEdit(index, row) {
      const id = row.id
      this.$router.push({path:`edit/${id}`})
    },


    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.pagination.page = 1
      this.getRecords()
    },
    handleCurrentChange(val) {
      this.pagination.page = val
      this.getRecords();
    },
    //多选
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    }
  },
  mounted() {
    this.getRecords()
  }
}
</script>

<style>

.table-img{
  width: 50px;
  height: 50px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 100px;
  height: 100px;
  display: block;
}
</style>


